package 游游的字母串;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int n = s.length();
        int res = 0x3f3f3f3f;
        for (int i = 0; i < 26; i++) {
            int step = 0;
            for (int j = 0; j < n; j++) {
                char ch = (char) ('a' + i);
                int t = Math.abs(ch - s.charAt(j));
                step += Math.min(t, 26 - t);
            }
            res = Math.min(step, res);
        }
        System.out.println(res);
    }
}